package se.sll.itintegration.catalogue.gui.entity;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author khaleddaham
 * @author Jiri Uosukainen
 */
@SuppressWarnings("PMD.UnusedPrivateField")
@Entity
@Data
@ToString(exclude = {"users"})
@EqualsAndHashCode(exclude = {"users"})
@Table(name = "careunit")
public class CareUnitEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private Long id;
    @NotNull
    private String hsaID;

    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "careUnits")
    private Set<UserEntity> users;

    public CareUnitEntity() {
    }

    public CareUnitEntity(String hsaID) {
        this.hsaID = hsaID;
    }
}
